package com.cqeec.ui;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class BookEditPanel extends JPanel {
	JLabel lbIsbn;
	JTextField txtIsbn;
	JLabel lbName;
	JTextField txtName;
	JLabel lbPrice;
	JTextField txtPrice;
	JLabel lbAuthor;
	JTextField txtAuthor;
	JComboBox xbType;
	JLabel lbType;
	JLabel lbPublisher;
	JTextField txtPublisher;
	JLabel lbPublishDate;
	JTextField txtPublishDate;
	JLabel lbstocknum;
	JTextField txtstocknum;
	String flag = "";
	public BookEditPanel(String flag) {
		this.flag = flag;
		BookFrame.lbState.setText("状态：数据填写后请保存");
		BookFrame.saveBtn.setEnabled(true);
		BookFrame.returnBtn.setEnabled(true);
		BookFrame.addBtn.setEnabled(false);
		BookFrame.modBtn.setEnabled(false);
		BookFrame.delBtn.setEnabled(false);
		BookFrame.findBtn.setEnabled(false);
		this.setLayout(null);
		initGUI(flag);
	}
    //GUI初始化
	private void initGUI(String flag) {
		try {
			lbIsbn = new JLabel();
			this.add(lbIsbn);
			lbIsbn.setText("图书编号:");
			lbIsbn.setBounds(50, 26, 72, 15);
			txtIsbn = new JTextField();
			this.add(txtIsbn);
			txtIsbn.setBounds(122, 23, 187, 22);
			if (flag.equals("edit")){
				txtIsbn.setEditable(false);
			}
			
			lbName = new JLabel();
			this.add(lbName);
			lbName.setText("图书名称:");
			lbName.setBounds(50, 66, 72, 15);
			txtName = new JTextField();
			this.add(txtName);
			txtName.setBounds(122, 63, 187, 22);

			lbType = new JLabel();
			this.add(lbType);
			lbType.setText("图书类别:");
			lbType.setBounds(50, 106, 72, 15);
			ComboBoxModel xbBoxModel = new DefaultComboBoxModel(new String[] {
					"经济管理", "计算机", "文学", "小说", "社会科学", "考试辅导" });
			xbType = new JComboBox();
			this.add(xbType);
			xbType.setModel(xbBoxModel);
			xbType.setBounds(122, 103, 187, 22);
			
			lbAuthor = new JLabel();
			this.add(lbAuthor);
			lbAuthor.setText("图书作者:");
			lbAuthor.setBounds(50, 146, 72, 15);
			txtAuthor = new JTextField();
			this.add(txtAuthor);
			txtAuthor.setBounds(122, 143, 187, 22);
			
			lbPublisher = new JLabel();
			this.add(lbPublisher);
			lbPublisher.setText("出版社:");
			lbPublisher.setBounds(50, 186, 72, 15);
			txtPublisher = new JTextField();
			this.add(txtPublisher);
			txtPublisher.setBounds(122, 183, 187, 22);
			
			lbPublishDate = new JLabel();
			this.add(lbPublishDate);
			lbPublishDate.setText("出版日期:");
			lbPublishDate.setBounds(50, 226, 72, 15);
			txtPublishDate = new JTextField();
			txtPublishDate.setToolTipText("输入格式：yyyy-MM-dd");
			this.add(txtPublishDate);
			txtPublishDate.setBounds(122, 223, 187, 22);
			
			lbPrice = new JLabel();
			this.add(lbPrice);
			lbPrice.setText("图书价格:");
			lbPrice.setBounds(50, 266, 72, 15);
			txtPrice = new JTextField();
			txtPrice.setToolTipText("输入数字");
			this.add(txtPrice);
			txtPrice.setBounds(122, 263, 187, 22);
			
			lbstocknum = new JLabel();
			this.add(lbstocknum);
			lbstocknum.setText("图书数量:");
			lbstocknum.setBounds(50, 306, 72, 15);
			txtstocknum = new JTextField();
			txtstocknum.setToolTipText("输入整数");
			this.add(txtstocknum);
			txtstocknum.setBounds(122, 303, 187, 22);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
